home *** CD-ROM | disk | FTP | other *** search
-
-
- GENERAL INPUT ROUTINE
-
- The Archimedes provides an excellent interface between an application
- program and the user: the WIMP manager. This should be used wherever
- possible by such applications software. It does, however, have one
- drawback. Many programs require the input of data; the processing of
- data is, after all, what computers do best. It will therefore be
- necessary for the user to type in such data. What is needed, is a way of
- managing and controlling that exchange, validating entries and
- monitoring all input.
-
- Included here is a set of such routines. They provide a whole host
- of facilities, all of which may be selected by the programmer. Wherever
- possible, they also possess room for expansion, allowing additions to be
- made. For each routine I have included a worded description of the
- functions provided, followed by a technical discussion of the procedures
- and functions used.
-
- There are also a number of service routines, which I have added since
- they may be of some use in other applications software.
-
- Input Routine
-
- Call Syntax: PROCIN(HORIZ%, VERT%, LGTH%, TYPE%)
-
- HORIZ% Horizontal position of input on screen
- VERT% Vertical position of input
- LGTH% Length of input
- TYPE% Type of input required
-
- This routine is designed to eliminate typing errors. When called, the
- routine places on the screen a set of inwardly facing arrows, > <. The
- location of these brackets, and the seperation between them, are
- determined by the input parameters to the routine. The entry asked for
- by the program is then made within the brackets. It is not possible to
- move the cursor away from that area, provided the cursor editing keys
- have been disabled with *FX4,1. Once the size and position of the input
- required is determined, the only other requirement of the routine is the
- type of data it is to accept.
-
- Using TYPE%, it is possible to select one of four basic input types,
- plus any number of other optional routines. At present, however, only
- five additional functions are provided by the system, although extending
- this is very straightforward.
-
- TYPE% is entered as, in effect, the decimal form of a binary number.
- Basically, the number contained in TYPE% is converted from decimal to
- binary, and then the procedures act on the condition of individual bit
- settings as described below.
-
- Bits 0 and 1.
-
- These are combined to provide a number ranging from 0 to 3, in effect
- they identify which of the four basic input types have been selected.
- They may be described as follows.
-
- 0 General Alphanumeric Input
- 1 Alphabetic keys only
- 2 Numeric keys only
- 3 Return only
-
- If, for example, option 1 is selected, only alphabetic keys may be used.
- The routine will accept a-z, A-Z and the space bar. Any other key
- pressed will be ignored by the routine. The numeric setting will only
- allow numeric digits, a point, '.', and a minus sign. It also permits
- the use of 'Z', which has a special meaning as described later.
-
- The remaining bits of the number, when set, call into operation
- procedures which have the following effects.
-
- Bit Decimal Value Use Flag Set
- 2 4 Restricts input to return only FLAG(1)
- 3 8 Prints BACK$ instead of spaces FLAG(2)
- If this is used, and BACK$ has
- been set, BACK$ is printed between
- the brackets instead of spaces.
- 4 16 Checks number validity if set FLAG(3)
- This only allows one '-' and
- one '.' per entry.
- 5 32 Test to see if entry purely
- numeric. FLAG(4)
- 6 64 Treats type-in as a password FLAG(5)
-
-
- The output from the routine comes in various forms.
-
- AN$ Holds the output as a string
- AN Holds the value of AN$ if the base type was numeric
- FLAG(0) Set if the entry was 'Z'
-
- This last flag setting is used to determine if the user wishes to escape
- from the function and return to a previous level or menu. Anyone
- familiar with other versions of Basic may recall CTRL-Z, which halts
- execution in a similay way.
-
- So, to accept a 12 character password at position TAB(20,10) on the
- screen, the following should be issued:
-
- PROCIN(20,10,12,64)
-
- €PE
- Technical Explanation:
-
- PROCIN consists mainly of three REPEAT...UNTIL loops. On entry,
- PROCLIMITS is called. This routine takes the value submitted in TYPE%
- and translates it into the various condition flags. On exit from LIMITS,
- the flags in the array FLAG(10) have been set as indicated above, with
- TYPE% containing a number in the range 0 to 3, which is the base input
- type.
-
- PROCSPACE then displays the input brackets (filled with BACK$ if FLAG(2)
- has been set. The routine then enters into its main loop, scanning the
- keyboard for depressed keys. The ASCII value of any key pressed is helf
- in CHAR. CHAR is then tested by FNVALID_CHAR to ensure that it is valid
- according to the strictures of the base input type (held in TYPE%). If
- it is invalid, it is simply ignored. If the character is valid, it is
- added to AN$. It is also displayed on the screen. This is achieved by
- PROCSHOW_CHAR, which will display a # symbol if a password input has
- been requested.
-
- If the character entered is delete, the last character of AN$ is removed
- and the cursor is backspaced. If the input has already reached the
- maximum length, a beep is issued and the character ignored. (These two
- functions handled by DELCHECK and SIZECHECK respectively).
-
- The program loops until RETURN is pressed.
-
- At this point the entry is complete. The routine now has the opportunity
- of testing the entry according to the wishes of the programmer.
-
- PROCDECIMAL scans the entered string, searching for the minus sign or
- decimal point, '-' & '.'. If more than one of each is detected, an error
- message is displayed (via PROCERROR), and a flag is set to indicate
- this. Provided the type-in is correct the flag is left clear and control
- passes on.
-
- PROCNUMERIC_CHECK tests the entry to see if it is purely numeric in
- nature. (It is assumed that a base input type has been used). This
- routine can then inform the program that in fact the entry was purely
- numeric.
-
- Single Character Input Routine
-
- Call Syntax: PROCIN2(HORIZ%,VERT%,VALID$)
-
- HORIZ% Horizontal position of input
- VERT% Vertical position of input
- VALID$ Valid Characters
-
- This routine may be used to accept a single keystroke from the keyboard.
- To differentiate this from the main input routine, the brackets used are
- curved, ie ( ). On entry to the routine, HORIZ% AND VERT% contain the
- coordinates of the input, while VALID$ is a string composed of all the
- legally acceptable keys for the routine to test.
-
- On exit from the routine, AN$ contains the key actually pressed, and AN
- the position of that character within VALID$.
-
- As with PROCIN, FLAG(0) will be set to 1 if the string entered is 'Z'.
-
- Compaction Routine
-
- Call Sytax: PROCCOMPACT(NUM%,SIZE%)
-
- NUM% Number to be packed
- SIZE% Size of destination string in bytes
-
- This routine accepts a signed numeric integer and transforms it to a
- binary packed string. This is useful if the number is to be stored as
- part of a data record for which the standard file format is
- unwieldy.Since the routine also stores the sign of the number, it is
- vital that the value of SIZE be large enough to take into account the
- sign. For example, the largest number that can be held in 1 byte is
- +127, the smallest -127.
-
- The packed string is returned as BIN$.
-
- Expansion Routine
-
- Call Syntax: PROCEXPAND(BINS$,SIZE%)
-
- BIN$ Compressed Number
- SIZE% Size of number
-
- This routine reverses the action of PROCCOMPACT, by returning an integer
- from a compacted string.
-
- Error Routine
-
- Call Synatx: PROCERROR(Error%)
-
- Error% The required error number
-
- This routine will display an error message in the event of a program
- trapping an error of some kind. The Error messages themselves are
- predefined and held in an array Error$, which is declared and filled by
- the routine PROCINIT_SYS. INIT_SYS is one once, on first entry into any
- program using these routines. Basically, the procedure uses a case
- statement to determine a suitable screen location for the error message.
- I have selected a line one up from the bottom of the screen, and roughly
- central. It would be quit straightforward (using DIV), to ensure that
- the text was centred exactly, in which case the HLOC% field would not be
- required as a start point, but could be modified to hold the width of
- the screen in characters.
-
- The routine displays the message at the calculated point, emits a Bell
- character (VDU 7), pauses for 0.75 seconds, then clears away the message
- and exits. It is a very simple case to extend the dimension of Error$
- and add as many error messages as are required by an application
- program. It would, however, required some modification in order to
- operate correctly within a Window from the WIMP environment.
-
-
- Delay Routine
-
- Call Syntax: PROCDELAY(DELAY%)
-
- DELAY% Required pause in 100ths of a second.
-
- This routine halts the program for the specified length of time.
-
- Format Routine
-
- Call Syntax: PROCFORMAT(AMOUNT$,LGTH%)
-
- AMOUNT$ String to be reformatted
- LGTH% Required length of output string
-
-
- This routine will accept a string input and a specified length. It will
- then evaluate the string as a numerical expression of currency. The
- object of the procedure is to return to the program a new string, which
- contains the amount received in a formatted state. For example,
-
- the string ".1" with a length specified of 5, would return,
-
- " 0.10" to the program.
-
- The procedure can handle negative numbers as well as positive, although
- care should be taken to ensure that space for a minus sign is included
- in the length of the return string specified.
-
-
- Restore Routine
-
- Call Syntax: PROCRESTORE(LABEL$)
-
- LABEL$ Label of DATA block to be located
-
- This routine will restore the BASIC data pointer to a given block of
- data in the program, provided that the block is prefixed with a label
- string. This label is then passed to PROCRESTORE as the only input
- parameter. The routine then scans down through all available DATA
- statements until the desired one is reached. Note: if no match is found
- the program will abort with an 'Out of Data' error. Note also (I cobbled
- this routine from Risc User, but it is so useful I thought I would
- include it anyway).
-
- Initialise Routine
-
- Call Syntax: PROCINIT_SYS
-
- This routine is used to declare all of the system variables used by the
- above procedures and functions. The large block of numbers represent the
- ascii codes for the various base input types. Space has been left to add
- additional error messages. There is also room to add declarations of
- other arrays should this be necessary, although it would be far more
- sensible to define another array called INIT_PROG, which could then be
- used to declare any other variables used by the program. i.e., reserve
- INIT_SYS for system variables only.
-
- So there we are. The procedures listed are by no means complete. They
- all work in the manner explained (at least, I haven't found any bugs
- yet!), and provide a useful service in a program. They are all capable
- of extension, and, I have no doubt, improvement. If anyone out there
- spots a potential bug, or has a suggestion for the improvement of any of
- the above listed routines, please encourage them to write in and air
- their views.
-
- I am revising and working on these on a daily basis, and will endeavour
- to keep you informed of any more which I develop in the future.
-
- One thing that I would be interested to know concerns the line numbering
- which I have employed, with each procedure starting at a 100 boundry. In
- my opinion this makes locating such a procedure or function fairly
- straightforward and, I believe, neatens the look of the proram. Any
- comments?
-